﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AgentJohnsonService.cs" company="Jakob Christensen">
//   Copyright (C) by Jakob Christensen
// </copyright>
// <summary>
//   Defines the <see cref="AgentJohnsonService" /> class.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace AgentJohnson.Options
{
  using JetBrains.Application;
  using JetBrains.Application.Communication;
  using JetBrains.Application.Settings;

  /// <summary>
  /// Defines the <see cref="AgentJohnsonService"/> class.
  /// </summary>
  [ShellComponent]
  public class AgentJohnsonService
  {
    #region Constants and Fields

    /// <summary>
    /// The my proxy settings reader field.
    /// </summary>
    private readonly WebProxySettingsReader myProxySettingsReader;

    /// <summary>
    /// The my settings store field.
    /// </summary>
    private readonly ISettingsStore mySettingsStore;

    #endregion

    #region Constructors and Destructors

    /// <summary>
    /// Initializes a new instance of the <see cref="AgentJohnsonService"/> class.
    /// </summary>
    /// <param name="proxySettingsReader">
    /// The proxy settings reader.
    /// </param>
    /// <param name="settingsStore">
    /// The settings store.
    /// </param>
    public AgentJohnsonService(WebProxySettingsReader proxySettingsReader, ISettingsStore settingsStore)
    {
      this.myProxySettingsReader = proxySettingsReader;
      this.mySettingsStore = settingsStore;
    }

    #endregion

    #region Public Methods and Operators

    /// <summary>Gets the client.</summary>
    /// <returns>Returns the client.</returns>
    public AgentJohnsonSettings GetSettings()
    {
      var boundSettings = this.mySettingsStore.BindToContextTransient(ContextRange.Smart((lt, contexts) => contexts.Empty));

      var settings = boundSettings.GetKey<AgentJohnsonSettings>(SettingsOptimization.OptimizeDefault);

      return settings;
    }

    #endregion
  }
}